<?php
	require_once("../utils/query.php");
	
	$storeitemid = $_POST["storeitemid"];
	if (!$storeitemid)
		die("Required field not supplied.");
	
	$result = execute_query(
		"SELECT name, type FROM StoreItemCards INNER JOIN cards_lu ON StoreItemCards.cardid = cards_lu.full_id WHERE front=1 AND storeitemid=%s",
		$storeitemid
	);
	
	$count = 0;
	$overflow = 16;
	
	$total = mysql_num_rows($result);
	$columns = ($total + $overflow - 1) / $overflow;
	$overflow = $total / $columns;
?>
<table>
	<tr>
		<td>
			<?php
				while ($row = mysql_fetch_array($result))
				{
					$name = $row[0];
					$type = $row[1];
					
					$color = "#000000";
					switch ($type)
					{
						case 1:
							$color = "#eb0000";
							break;
						case 2:
							$color = "#ccc84d";
							break;
						case 3:
							$color = "#0104e7";
							break;
						case 10:
							$color = "#cf46c7";
							break;
						case 20:
							$color = "#727272";
							break;
					}
				
					if ($count > $overflow)
					{
						$count = 0;
						echo("</td><td>");
					}
			?>
					<span class="itemcard" style="color:<?php echo $color; ?>;"><?php echo $name; ?></span>
					<br/>
			<?php
					++$count;
				}
			?>
		</td>
	</tr>
</table>
